<%@ include file="/WEB-INF/views/jsp/include/include.jsp"%>
<html>
<head>
<title>Hand In Hand</title>
<%@ include file="/WEB-INF/views/jsp/include/head.jsp"%>
</head>
<body>
	<%@ include file="/WEB-INF/views/jsp/include/header.jsp"%>
	<%@ include file="/WEB-INF/views/jsp/include/navigator.jsp"%>
	<%@ include file="/WEB-INF/views/jsp/include/errors.jsp"%>

	<div class="container-fluid">
		<div align="center" class="row">
			<c:if
				test="${requestViewForm.request.community.privacy == 'PUBLIC' || requestViewForm.communityMember.user != null}">
				<div class="btn-group" role="group" aria-label="...">
					<c:if test="${requestViewForm.communityMember.user != null }">
						<button class="btn btn-default" type="button"
							onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/newEvent"></spring:url>'">
							Create Event</button>
					</c:if>
					<button class="btn btn-default" type="button"
						onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/events"></spring:url>'">
						Events of Community</button>
				</div>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<div class="btn-group" role="group" aria-label="...">
					<c:if test="${requestViewForm.communityMember.user != null }">
						<button class="btn btn-default" type="button"
							onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/newRequest"></spring:url>'">
							Create Request</button>
					</c:if>
					<button class="btn btn-default" type="button"
						onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/requests"></spring:url>'">
						Requests of Community</button>
				</div>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<div class="btn-group" role="group" aria-label="...">
					<c:if test="${requestViewForm.communityMember.user != null }">
						<button class="btn btn-default" type="button"
							onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/newOffer"></spring:url>'">
							Create Offer</button>
					</c:if>
					<button class="btn btn-default" type="button"
						onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/offers"></spring:url>'">
						Offers of Community</button>
				</div>
				<hr>
			</c:if>
		</div>


		<!--  Left Column for Community Name and Info -->
		<div style="height: 100% !important; word-break: break-word;"
			class="col-xs-3">
			<div
				style="border: 1px solid #b78f41 !important; border-radius: 10px;"
				class="col-xs-12">
				<img class="col-xs-10 col-xs-offset-1" style="margin-top: 5px;"
					src=<c:url value="/resources/images/community-icon.png"/>
					class="img-rounded"> <strong style="font-size: 16pt;">
					<c:out value="${requestViewForm.request.community.name}"></c:out>
				</strong><br>
				<button style="margin-top: 5px; margin-bottom: 5px;"
					class="btn btn-primary col-xs-12" type="button"
					onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}"></spring:url>'">
					Community Wall</button>
				<c:if test="${requestViewForm.moderatedRequest != null }">
					<button style="margin-top: 5px; margin-bottom: 5px;"
						class="btn btn-primary col-xs-12" type="button"
						onclick="location.href='<spring:url value="/communities/${requestViewForm.request.community.id}/requests/${requestViewForm.request.id}/editRequest"></spring:url>'">
						Edit Request</button>
				</c:if>
			</div>
		</div>

		<div id="center" class="col-xs-6">

			<form:form id="requestViewForm" modelAttribute="requestViewForm"
				method="post" action="./${requestViewForm.request.id}/respond">
				<!-- Post Submit -->
				<c:if
					test="${requestViewForm.request.community.privacy == 'PUBLIC' || requestViewForm.communityMember.user != null}">
					<div align="center"
						style="border: 1px solid #b78f41 !important; display: inline; border-radius: 10px; padding-bottom: 10px; padding-top: 10px;"
						class="col-xs-12">
						<label>Request Creator : </label>
						<c:out
							value="${requestViewForm.request.creator.name} ${requestViewForm.request.creator.surname}"></c:out>
						<br> <label>Name : </label>
						<c:out value="${requestViewForm.request.name}"></c:out>
						<br> <label>Ending Time : </label>
						<c:out value="${requestViewForm.request.expirationDate}"></c:out>
						<br> <label>Information : </label>
						<c:out value="${requestViewForm.request.description}"></c:out>
						<br> <br>
						<c:if test="${requestViewForm.request.activityType == 'GOODS'}">
							<label>Requested items:</label>
							<br>
							<span>Amount : </span> ${requestViewForm.request.goods.targetAmount} <br>
							<span>Unit : </span> ${requestViewForm.request.goods.unit} <br>
							<span>Item name: </span> ${requestViewForm.request.goods.itemName} <br>
							<span>Responded amount: </span> ${requestViewForm.request.goods.respondedAmount} <br>
							<span>Your contribution: </span> ${requestViewForm.userContribution} <br>
							<c:if
								test="${requestViewForm.request.goods.targetAmount == requestViewForm.request.goods.respondedAmount}">
								<label>COMPLETED!</label>
								<br>
							</c:if>
							<c:if
								test="${requestViewForm.request.goods.targetAmount != requestViewForm.request.goods.respondedAmount}">
								<label>Would you like to respond to this request? </label>
								<br>
								<span>Respond with </span>
								<form:input size="5" cssStyle="text-align: right;"
									path="goodsAmount" />
								<span>${requestViewForm.request.goods.unit}
									${requestViewForm.request.goods.itemName}</span>
								<br>
								<button type="submit" class="btn btn-primary"
									style="float: right; margin-right: 70px; margin-top: 2px;">Respond</button>
							</c:if>


						</c:if>
						<c:if test="${requestViewForm.request.activityType == 'SERVICES'}">
							<label>Requested service:</label>
							<br>
							<span>Service name : </span> ${requestViewForm.request.service.requiredSkill.name} <br>
							<span>Number : </span> ${requestViewForm.request.service.requiredNumber} <br>
							<span>Responded amount: </span> ${requestViewForm.request.service.respondedAmount} <br>
							<span>Your contribution: </span> ${requestViewForm.userContribution} <br>
							<c:if
								test="${requestViewForm.request.service.requiredNumber == requestViewForm.request.service.respondedAmount}">
								<label>COMPLETED!</label>
								<br>
							</c:if>
							<c:if
								test="${requestViewForm.request.service.requiredNumber != requestViewForm.request.service.respondedAmount}">
								<label>Would you like to respond to this request? </label>
								<br>
								<span>Respond with </span>
								<form:input size="5" cssStyle="text-align: right;"
									path="servicesAmount" />
								<span>${requestViewForm.request.service.requiredSkill.name}</span>
								<br>
								<button type="submit" class="btn btn-primary"
									style="float: right; margin-right: 70px; margin-top: 2px;">Respond</button>
							</c:if>
						</c:if>
					</div>
				</c:if>
			</form:form>


			<br>
			<!-- Post Submit -->
			<form:form id="requestViewForm" modelAttribute="requestViewForm"
				method="post"
				action="../requests/${requestViewForm.request.id}/post">
				<c:if test="${requestViewForm.communityMember.user != null}">
					<div align="center"
						style="border: 1px solid #b78f41 !important; display: inline; border-radius: 10px; padding-bottom: 10px; padding-top: 10px;"
						class="col-xs-12">
						<table style="width: 74%;">
							<tr>
								<td style="width: 90%;"><form:textarea
										style="width:100%; height:54px; resize:none;" path="post" />
								</td>
								<td>
									<button class="btn btn-primary" style="height: 54px;"
										type="submit">Post</button>
								</td>
							</tr>
						</table>
					</div>
				</c:if>
				<!-- Post View -->
				<c:if
					test="${requestViewForm.request.community.privacy == 'PUBLIC' || requestViewForm.communityMember.user != null}">
					<c:if test="${not empty requestViewForm.wallElements }">
						<div
							style="border: 1px solid #b78f41 !important; border-radius: 10px; padding-bottom: 10px; padding-top: 10px;"
							class="col-xs-12">
							<c:forEach var="element" items="${requestViewForm.wallElements}">
								<div
									style="border: 1px solid #898787 !important; border-radius: 10px; margin-top: 4px; margin-bottom: 4px; padding-bottom: 3px; padding-top: 3px;"
									class="col-xs-12">


									<img style="margin-top: 5px;" class="col-xs-2"
										src=<c:url value="/resources/images/maleicon.jpg"/>> <span>
										<a> ${element.user.name } ${element.user.surname }</a> 's post
									</span> <br> ${element.context}
								</div>
							</c:forEach>
						</div>
					</c:if>
				</c:if>
			</form:form>
		</div>
		<!-- 				end of wall -->

		<!-- 			end of center -->
<div class="col-xs-3">
		<!--  RECOMMENDATION	 -->
		<div
					style="border: 1px solid #b78f41 !important; border-radius: 10px; margin-left: 3px; margin-right: 3px; padding-bottom: 10px; padding-top: 10px;"
					class="col-xs-8">
					<strong>RECOMMENDATIONS</strong>
				<c:forEach var="request" items="${requestViewForm.requestList}">
				<div
							style="overflow: hidden; border: 1px solid #898787 !important; border-radius: 10px; margin-top: 4px; margin-bottom: 4px; margin-left: 2px; margin-right: 2px; padding-bottom: 3px; padding-top: 3px;"
							>
						
							<div style="padding-top: 6px; padding-bottom: 6px; padding-left: 4px; padding-right: 4px;">
								<a class="list-group-item-warning"
									href="<spring:url value='/communities/${request.community.id}/requests/${request.id}'></spring:url>">
									<strong style="font-size: 0.9em; overflow-wrap: break-word;">${request.name}</strong>
								</a> <br> <span style="font-size: 0.7em; color: gray;">Due: ${request.expirationDate}</span><br> <span
									style="font-size: 0.8em; font-style: oblique; height: 30px; overflow-wrap: break-word;">${request.description}</span>

							</div>
						</div>
				</c:forEach>

		
		</div>
</div>
	</div>
	<%@ include file="/WEB-INF/views/jsp/include/footer.jsp"%>

</body>
</html>